package net.oschina.app.com.testcase.collection;

import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.robotium.solo.Solo;

import net.oschina.app.AppStart;

/**
 * Created by Administrator on 2018/3/13.
 */

public class Collection2 extends ActivityInstrumentationTestCase2 {
    private Solo solo;

    public Collection2() throws Exception {
        super(AppStart.class);

    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());

    }

    public void testName() throws Exception {
        solo.clickOnView(solo.getView("net.oschina.app:id/nav_item_me"));
        solo.clickOnView(solo.getView("net.oschina.app:id/iv_portrait"));
        EditText nameET = (EditText) solo.getView("net.oschina.app:id/et_username");
        solo.clearEditText(nameET);
        EditText pwdET = (EditText) solo.getView("net.oschina.app:id/et_password");
        solo.clearEditText(pwdET);
        solo.enterText(nameET, "735723619@qq.com");
        solo.enterText(pwdET, "12345678");
        solo.clickOnView(solo.getView("net.oschina.app:id/btn_login"));
        solo.sleep(3000);
        //校验是否成功登录
        assertTrue(solo.searchText("aotu12345aotu", true));

        solo.clickOnView(solo.getView("net.oschina.app:id/nav_item_news"));
        TextView tvtitle = (TextView) solo.getView("net.oschina.app:id/tv_title", 1);
        String expecte = tvtitle.getText().toString();
        solo.clickOnView(tvtitle);
        solo.sleep(5000);
        View fav = solo.getView("net.oschina.app:id/iv_fav");
        solo.clickOnView(fav);
        assertTrue(solo.searchText("收藏成功", true));
        solo.goBack();
        solo.clickOnView(solo.getView("net.oschina.app:id/nav_item_me"));
        solo.clickOnView(solo.getView("net.oschina.app:id/ly_favorite"));
        TextView favtitle = (TextView) solo.getView("net.oschina.app:id/tv_favorite_title");
        String actual = favtitle.getText().toString();//获取实际文本
        //校验预期文本与实际文本是否一致
        assertTrue(expecte.contains(actual));
        solo.sleep(5000);

    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();
    }
}
